function oConfirmEngine(engine) {
  this.engine = engine;
}

oConfirmEngine.prototype = {
  // 绿色
  success: function (content, confirmCallback, cancelCallback) {
    return this.renderConfirm(content, null, "success", null, null, confirmCallback, cancelCallback);
  },
  // 黄色
  warning: function (content, confirmCallback, cancelCallback) {
    return this.renderConfirm(content, null, "warning", null, null, confirmCallback, cancelCallback);
  },
  // 红色
  error: function (content, confirmCallback, cancelCallback) {
    return this.renderConfirm(content, null, "error", null, null, confirmCallback, cancelCallback);
  },
  // 蓝色
  info: function (content, confirmCallback, cancelCallback) {
    return this.renderConfirm(content, null, "info", null, null, confirmCallback, cancelCallback);
  },
  // 确认面板
  renderConfirm: function (content, title, type, confirmText, cancelText, confirmCallback, cancelCallback) {
    // 调试请在手机模式下调试，因为平台模式下不会加载vant框架。
    if (this.engine.tools.isMobile()) {
      this.engine.vue.$dialog.confirm({
        title: title || '提示',
        message: content,
        confirmButtonText: confirmText || '确定',
        cancelButtonText: cancelText || '取消',
      }).then(() => {
        if (confirmCallback) {
          confirmCallback(true);
        }
      }).catch(() => {
        if (cancelCallback) {
          cancelCallback(false);
        }
      });
    }
    // 平台端
    else {
      return this.engine.vue.$confirm(content, title || '提示', {
        confirmButtonText: confirmText || '确定',
        cancelButtonText: cancelText || '取消',
        type: type,
      }).then(() => {
        if (confirmCallback) {
          confirmCallback(true);
        }
      }).catch(action => {
        if (cancelCallback) {
          cancelCallback(false);
        }
      });
    }
  },
}

export {
  oConfirmEngine
}


